package minFlips

func MinFlips(grid [][]int) int {
	r, c := len(grid), len(grid[0])
	count_r := 0
	//按行
	for i := 0; i < r; i += 1 {
		left, right := 0, c-1
		for left < right {
			if grid[i][left] != grid[i][right] {
				count_r += 1
			}
			left += 1
			right -= 1
		}
	}
	count_c := 0
	// 按列
	for i := 0; i < c; i += 1 {
		left, right := 0, r-1
		for left < right {
			if grid[left][i] != grid[right][i] {
				count_c += 1
			}
			left += 1
			right -= 1
		}
	}
	return min(count_r, count_c)

}
